﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Menu : MonoBehaviour
{
    private GameObject manager;

    private GameObject cannon, tesla;

    private ResourceManager resM;
    // Start is called before the first frame update
    void Start()
    {
        manager = GameObject.Find("GameManager");
        cannon = Resources.Load("Prefab/Turrent")as GameObject;
        tesla = Resources.Load("Prefab/Turrent_Tesla")as GameObject;
        resM = GameObject.Find("GameManager").GetComponent<ResourceManager>();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void destroyself()
    {
        manager.GetComponent<Construction>().killMenu();
    }

    public void makeCannon()
    {
        if (resM.BuildCost(0))
        {
            Instantiate(cannon, this.gameObject.transform.position-new Vector3(0,1.8f,0),Quaternion.identity);
        }
        manager.GetComponent<Construction>().killMenu();
    }
    
    public void makeTesla()
    {
        if (resM.BuildCost(1))
        {
            Instantiate(tesla, this.gameObject.transform.position-new Vector3(0,1.8f,0),Quaternion.identity);
        }
        manager.GetComponent<Construction>().killMenu();
    }
}
